<?php
/**
 * Created by PhpStorm.
 * User: ASUS
 * Date: 2021/12/6
 * Time: 20:50
 */

//1.登入判断： 用户名：admin
//                   密码：   888888
//2.登入成功，则设置一个cookies,名字：Token,值md5(用户名+密码+时间戳),效期：24小时
//3.用户中心页面：
//		判断cookies是否存在。
//		上传头像，预览功能；上传成功后要展示头像。

//echo '设置COOKIES';
//
//setcookie('username','Token',time()+24*3600);
//
//echo '读取COOKIES';

if (!empty($_COOKIE['username'])){
    echo '用户编号:'.$_COOKIE['username'];
    echo '<br/>';
    echo '<a href="login.php">退出登录</a>';
}
else{
    echo '您尚未登录，请先登录！';
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>上传头像</title>
</head>
<body>
<form action="uploadphoto.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id="file" multiple="multiple" onchange="UploadPhoto();">
    <br/><br/>
    <img src="" id="uploads" style="width: 300px; height: 300px;">
    <br/><br/>
    <input type="submit" value="上传头像">
</form>
</body>
<script type="text/javascript">
    var fileObj = document.getElementById('file');
    function UploadPhoto(){
        var files = fileObj['files'];
        var URL = window.URL || window.webkitURL;
        var imgURL = URL.createObjectURL(files[0]);
        document.getElementById('uploads').src = imgURL;
    }
    onload = function(){
        console.log(fileObj)
        fileObj.onchange = UploadPhoto;
    }
</script>
</html>